package Vistas;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import Controladores.ValidacionUsuario;

public class Login extends JFrame implements ActionListener {
	private static final long serialVersionUID = 1L;
	private JTextField txtUsuario;
	private JButton btnIngreso;
	private ValidacionUsuario vu;
	
	public Login() {
		this.txtUsuario = new JTextField(10);
		this.btnIngreso = new JButton("Ingreso");
		this.vu = new ValidacionUsuario(this);
		
		this.btnIngreso.addActionListener(this);
		
		this.add(new JLabel("Nro. Legajo: "));
		this.add(this.txtUsuario);
		this.add(this.btnIngreso);
		
		this.setSize(230, 100);
		this.setLayout(new FlowLayout());
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}

	public static void main(String[] args) {
		new Login();
	}


	public void actionPerformed(ActionEvent e) {
		int legajo;
		try {
			legajo = Integer.parseInt((this.txtUsuario.getText()));
			
		} catch (Exception ex) {
			legajo = 0;
		}
	
		this.vu.ValidaUsuario(legajo);
	}
	
	public void closeFrame() {
		this.dispose();
	}
	
	public void invalidUser() {
		this.txtUsuario.setText("");
		
		JOptionPane.showMessageDialog(null, "Usuario invalido");
	}
}
